

*** This do file creates figure A1
* If needed change global path to point to directory where files are stored on your computer
*global path "I:/DataSets5/Duncan/Dropbox/Recent Minimum Wage Changes/2020.12 NBER Update/JOLE Precommittment Replication"
global dtadir "$path/Data"
global tabdir "$path/Tables"
global figdir "$path/Figures"
global estdir "$path/Estimates"
global logdir "$path/Logfiles"

*****************************************************************************************************
************		                     2. Program for Stacked Dataset				     ************
*****************************************************************************************************

capture program drop gen_dataset 
program define gen_dataset 

	** syntax
	syntax, treatyear(varname) cohort(real)

	use "${path}\Data\ACSEventStudiesData.dta", clear
	
	keep if `treatyear' == `cohort' | `treatyear' ==.
	gen treat_stacked = 0
	replace treat_stacked = 1 if `treatyear' !=. /* treatment var is any cohort year */
	gen cohort = `cohort'  /* label reform */ 

	** recode years to be in event time 
	qui gen t = year - `cohort' + 1 
	qui replace t = -3 if inrange(t,-10,-3) 
	qui replace t = 5 if inrange(t,5,10) 
	
	* Generate sample indicators
	gen lowskilled = 0
	replace lowskilled = 1 if inrange(age,16,25) & dropout == 1

	gen young = 0
	replace young = 1 if inrange(age,16,21)

	gen primeage = 0
	replace primeage = 1 if inrange(age,26,54)

	gen highskill = 0
	replace highskill = 1 if  inrange(age,26,54) & educ > 6 
	
	* Generate logged minimum wage
	gen minwage = ln(effectiveminwage)

end

*****************************************************************************************************
************		                     3. Program for Event Studies				     ************
*****************************************************************************************************


capture program drop did_stacked
program define did_stacked

	*------------------------ 3.1 Syntax --------------------------

	syntax varlist(min=2 max=2), [xvar(string) pretrend(real 0) otherlab(string) panel(string)]

	local outcome `1'
	local sample = subinstr("`2'",",","",.)
	
	*------------------------ 3.2 Set Up --------------------------

	est clear
	
	* event time defintion and range
	cap drop tvar
	gen tvar = t + 4
	
	* generate sample tag
	cap drop sample
	gen sample = inrange(tvar, 1, 9) & `sample' == 1
	local ref = 0 + 4
	
	keep if sample == 1
	tab tvar

	*------------------------ 3.3 Event Study --------------------------
	
	* Set controls
	if "`otherlab'" == "nocontrols" {
	    local xvar
		local controlslabel `"no controls"'
	}
	
	else if "`otherlab'" == "basecontrols" {
	    local xvar age educ lnPersonalIncome HPI
		local controlslabel `"Base Controls"'
	}
	
	else if "`otherlab'" == "richcontrols" {
	    local xvar age educ lnPersonalIncome HPI D3lnPersonalIncome D3HPI
		local controlslabel `"Rich Controls"'
	}
	
	else {
	    local xvar
		local controlslabel `"None"'
	}
	
	* Set sample label
	if "`sample'" == "lowskilled" {
		local samplabel  `"Least-Skilled"'
	}
	
	else if "`sample'" == "young" {
		local samplabel `"Young"'
	}
	
	else if "`sample'"== "primeage" {
		local samplabel `"Prime Age"'
	}
	else if "`sample'" == "highskill" {
		local samplabel `"Prime Age Higher-Skilled"'
	}
	else {
		local samplabel `"None"'
	}
	
	* Stacked Event Study Regression Large Increaser Treated Group (Need to drop both small statutory increasers anmd indexers)
	eststo: reghdfe `outcome' b`ref'.tvar##i.treat_stacked `xvar' [pw=cmpwgt] if sample == 1 & indexer == 0 & StatIncreaserSmall == 0, absorb(statefip year) cluster(statefip)
	
	* Save coefficients
		* create matrix
		mat est = J( 9 , 8, .)
						
		* fill matrix with values of t, point estimates, and CI
		local n = 1
		foreach t of numlist -3/5 {
			* tnorm
			local tnorm = `t' + 4
			* event time
			mat est[`n',1]  = `t' - 0.1
			* normalized coefficient
			mat est[`n',2] =  _b[`tnorm'.tvar#1.treat_stacked]
			* lower CI
			mat est[`n',3] = _b[`tnorm'.tvar#1.treat_stacked] + invnorm(0.025)*_se[`tnorm'.tvar#1.treat_stacked]
			* upper CI
			mat est[`n',4] = _b[`tnorm'.tvar#1.treat_stacked] + invnorm(0.975)*_se[`tnorm'.tvar#1.treat_stacked]
			local n = `n' + 1
		}
		
	* Stacked Event Study Regression Small Increaser Treated Group (Need to drop large statutory increasers)
	eststo: reghdfe `outcome' b`ref'.tvar##i.treat_stacked `xvar' [pw=cmpwgt] if sample == 1 & StatIncreaserLarge == 0 & indexer == 0 & statefip != 23, absorb(statefip year) cluster(statefip)

		* fill matrix with values of t, point estimates, and CI
		local n = 1
		foreach t of numlist -3/5 {
			* tnorm
			local tnorm = `t' + 4
			* event time
			mat est[`n',5]  = `t' + 0.1
			* normalized coefficient
			mat est[`n',6] =  _b[`tnorm'.tvar#1.treat_stacked]
			* lower CI
			mat est[`n',7] = _b[`tnorm'.tvar#1.treat_stacked] + invnorm(0.025)*_se[`tnorm'.tvar#1.treat_stacked]
			* upper CI
			mat est[`n',8] = _b[`tnorm'.tvar#1.treat_stacked] + invnorm(0.975)*_se[`tnorm'.tvar#1.treat_stacked]
			local n = `n' + 1
		}
	
		* store coefficients to dataset
		cap drop est?
		svmat est
		
	
	
	*------------------------ 3.5 Plot  --------------------------


	graph twoway (scatter est2 est1, msymbol(circle) mc(black) lc(black)) ///
				(rspike est3 est4 est1, color(black) m(i)) ///
				(scatter est6 est5, msymbol(triangle) mc(black) lc(black)) ///
				(rspike est7 est8 est5, color(black) m(i) ///
					xline(0.5, lcolor(black) lpattern(dash)) xtitle("Year Relative to MW Increase", size(small)) ///
					yline(0, lcolor(black)) ytitle("Change in MW (Log Points)", size(small)) ///
					ylabel(, labsize(small) gmin gmax) ///
					xlabel(-3 "-3+" -2 "-2" -1 "-1" 0 "0" 1 "1" 2 "2" 3 "3" 4 "4" 5 "5+", labsize(small)) xscale(range(-3 5)) ///
					graphregion(c(white)) ///
					title("", size(small)) ///
					legend(order(1 "Large Increasers" 3 "Small Increasers") rows(1) region(lstyle(none)) size(small) symxsize(small) symysize(small)) ///
					name("`outcome'_`sample'_`otherlab'", replace)) 
					graph export "$figdir/`outcome'_`sample'_`otherlab'_small_large_noindexer_5-plus.pdf", replace

end

*****************************************************************************************************
************				          4. Graph								            *************
*****************************************************************************************************
#delimit cr

cap log close 

* start log file 
log using "${path}/Logfiles/policy-cohort-figure-2-cohort-state-FE-minwage-5-plus.log", replace

* Load data
use "${path}/Data/ACSEventStudiesData.dta", clear

tab legimpyear1

tab statefip if StatIncreaserLarge == 1
tab statefip if StatIncreaserSmall == 1
tab statefip if indexer == 1

* -------------------------- 2.1 Create Event Study Dataset for Increase --------------------------- 

tempfile stacked

* 2013
	gen_dataset, treatyear(legimpyear1) cohort(2013)
	qui save `stacked', replace
* 2014
	gen_dataset, treatyear(legimpyear1) cohort(2014)
	qui append using `stacked'
	qui save `stacked', replace 
* 2015
	gen_dataset, treatyear(legimpyear1) cohort(2015)
	qui append using `stacked'
	qui save `stacked', replace
* 2016
	gen_dataset, treatyear(legimpyear1) cohort(2016)
	qui append using `stacked'
	qui save `stacked', replace 
 * 2017
	gen_dataset, treatyear(legimpyear1) cohort(2017)
	qui append using `stacked'
	qui save `stacked', replace 
* 2019
	gen_dataset,  treatyear(legimpyear1) cohort(2019)
	qui append using `stacked'
	qui save `stacked', replace


* -------------------------- 2.2 Graph --------------------------- 

est clear

* young
	did_stacked minwage young, otherlab(nocontrols)
	
* Combine graphs to make a 4-panel figure
set graph on
graph dir // These named graphs are now in memory

grstyle init
grstyle color background white
grstyle graphsize x 8
grstyle graphsize y 7
grstyle set legend, nobox
